﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xfs;

namespace Xfs
{
    [XfsMessageHandler(XfsSenceType.XfsServer)]
    public class S4C_UserHandler : XfsAMRpcHandler<C4S_User, S4C_User>
    {
        protected override void Run(XfsSession session, C4S_User message, Action<S4C_User> reply)
        {
            ///检验帐号正确性？
            XfsUserComponent userComponent = XfsGame.XfsSence.GetComponent<XfsUserComponent>();

            XfsUser? user = userComponent.CheckPassword(message.Username, message.Password);

            Console.WriteLine(XfsTimeHelper.CurrentTime() + " " + this.GetType().Name + " 20. User." + message.Username + "/" + message.Password + " 验证通过...");

            if (user != null)
            {
                ///回复信息给客户端
                S4C_User response = new S4C_User() { RpcId = message.RpcId, Userid = user.Id, Username = user.Username, Password = user.Password };
                reply(response);

                ///发送小怪到服务器
                XfsGame.XfsSence.GetComponent<XfsUnitComponent>().SetMonsters(session);
            }
        }


    }
}